package fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.wangjin.menu.R;

import java.util.ArrayList;

import model.ArrangementItem;

/**
 * Created by wangjin on 15/6/17.
 */
public class Arrangement extends ListFragment{

    ArrangementItem[] arrangementItems;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        arrangementItems = new ArrangementItem[1];
        arrangementItems[0] = new ArrangementItem();
        arrangementItems[0].setTime("8:00 ~ 9:00");
        arrangementItems[0].getArrangements().add("草图设计");
        arrangementItems[0].getArrangements().add("原型设计");
        arrangementItems[0].getArrangements().add("程序编码");

        ListAdapter l = new ListAdapter(arrangementItems);
        setListAdapter(l);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.arrangment_layout,container,false);
        return v;
    }

    class ItemAdapter extends ArrayAdapter<String>{

        ArrayList<String> strings;

        public ItemAdapter(ArrayList<String> strings){
            super(getActivity(),0,strings);
            this.strings = strings;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null){
                convertView = getActivity().getLayoutInflater().inflate(R.layout.arrangement_item_item_layout,null);
                TextView t = (TextView)convertView.findViewById(R.id.textView5);
                t.setText(strings.get(position));
                return convertView;
            }else {
                return convertView;
            }
        }
    }

    class ListAdapter extends ArrayAdapter<ArrangementItem>{

        ArrangementItem[] arrangementItems;

        public ListAdapter(ArrangementItem[] arrangementItems){
            super(getActivity(),0,arrangementItems);
            this.arrangementItems = arrangementItems;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null){
                convertView = getActivity().getLayoutInflater().inflate(R.layout.arrangement_item_layout,null);
                TextView t = (TextView) convertView.findViewById(R.id.t1);
                t.setText(arrangementItems[position].getTime());
                ItemAdapter i = new ItemAdapter(arrangementItems[position].getArrangements());
                //ListView l = (ListView) convertView.findViewById(R.id.list);
                //l.setAdapter(i);
                return convertView;
            }else {
                return convertView;
            }
        }
    }

}
